package com.wxf.web;

import com.wxf.service.StudentService;
import com.wxf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/Educational/student/deleteStudentInfo")
public class DeleteStudentInfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1-获取请求参数
        req.setCharacterEncoding("utf-8");
        String stuId = req.getParameter("stuId");
        System.out.println("stuId="+stuId);

        // 2-后台处理
        StudentService studentService = new StudentServiceImpl();
        int influenceRow = studentService.deleteStudentInfo(Integer.parseInt(stuId));

        // 3-响应
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        if(influenceRow>0){
            pw.println("<script>alert('删除成功');location.href='GetStudentList'</script>");
        }else{
            pw.println("<script>alert('删除失败'>;location.href='GetStudentList'</script>");
        }
    }
}
